﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ZilLion.Service.Crm.Unities.IOC;
using ZilLion.Service.WebInfrastructure.Base;
using ZilLion.Service.WebInfrastructure.Filter;
using ZilLion.Service.WechatService.Domain;
using ZilLion.Service.WechatService.Domain.WebApiEntity.CRM;
using ZilLion.Service.WechatService.Domain.WebApiEntity.WechatCardModel;
using ZilLion.Service.WechatService.Domain.WebApiRepository.InterFace;

namespace ZilLion.Service.WechatService.Controllers
{
    [Route("Api/EasyQuery")]
    [AllowAnonymous]
    //[AuthorizationValidateAtrribute]
    public class EasyQueryController : WebApiBase
    {
        [Route("ConnectTest")]
        [HttpGet]
        public string ConnectTest(string RequestGuid)
        {
            return RequestGuid;
        }

        [Route("ChargeInfo")]
        [HttpGet]
        public ZzinfocsResponse GetChargeInfo()
        {
            GloabConfigCacheLoader Loader = GloabConfigCacheLoader.CreateGloabConfigCacheLoader(new WechatServiceContext());
            var item = Loader.GetZzinfocsCacheItem();
            if (item == null)
            {
                item = Loader.SetChargeInfo();
            }
            return new ZzinfocsResponse { Zzinfocss = item.infocs };
        }

        [Route("GetZklbSettingModel")]
        [HttpGet]
        public ZklbSettingResponse GetZklbSettingModel()
        {
            var CRMSettingRepository = ClassFactory.GetInstance<ICrmSettingRepository>();
            return CRMSettingRepository.GetZklbSettingModel();
        }

        [Route("GetKzSettingModel")]
        [HttpGet]
        public KzSettingModelResponse GetKzSettingModel()
        {
            var CRMSettingRepository = ClassFactory.GetInstance<ICrmSettingRepository>();
            return CRMSettingRepository.GetKzSettingModel();
        }

        [Route("SaveKzSettingModel")]
        [HttpPost]
        public KzSettingModel SaveKzSettingModel(KzSettingModel KzSetting)
        {
            var CRMSettingRepository = ClassFactory.GetInstance<ICrmSettingRepository>();
            return CRMSettingRepository.SaveKzSettingModel(KzSetting);
        }

        [Route("SaveZklbSettingModel")]
        [HttpPost]
        public ZklbSettingModel SaveZklbSettingModel(ZklbSettingModel ZklbSetting)
        {
            var CRMSettingRepository = ClassFactory.GetInstance<ICrmSettingRepository>();
            return CRMSettingRepository.SaveZklbSettingModel(ZklbSetting);
        }
    }
}